package com.kin.rich.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class CalendarFunction {

	
	public static String dateToString(Date date){
		try{
			//Calendar calendar = Calendar.getInstance();
			//calendar.setTime(date);
			SimpleDateFormat SDF=new SimpleDateFormat("yyyy-MM-dd");//格式化时间显示类型
		    return SDF.format(date);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "0000-00-00";
	}
	public static String dateToTimeString(Date date){
		try{
			//Calendar calendar = Calendar.getInstance();
			//calendar.setTime(date);
			SimpleDateFormat SDF=new SimpleDateFormat("HH:mm:ss");//格式化时间显示类型
		    return SDF.format(date);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "00:00:00";
	}
	public static String dateToDateTime(Date date){
		try{
			//Calendar calendar = Calendar.getInstance();
			//calendar.setTime(date);
			SimpleDateFormat SDF=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间显示类型
		    return SDF.format(date);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "0000-00-00 00:00:00";
		
	}

	public static Date StringToDate(String str){
		try{
			//Calendar calendar = Calendar.getInstance();
			//calendar.setTime(date);
			SimpleDateFormat SDF=new SimpleDateFormat("yyyy-MM-dd");//格式化时间显示类型
			return SDF.parse(str);
			//return SDF.format(date);
		}catch(Exception e){
			e.printStackTrace();
		}
		return new Date();
	}
	
	public static Date StringToDate2(String str){
		try{
			//Calendar calendar = Calendar.getInstance();
			//calendar.setTime(date);
			SimpleDateFormat SDF=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间显示类型
			return SDF.parse(str);
			//return SDF.format(date);
		}catch(Exception e){
			e.printStackTrace();
		}
		return new Date();
	}
	
	public static void main(String[] args){
		
		System.out.println(CalendarFunction.dateToDateTime(CalendarFunction.StringToDate("2010-01-01")));
	}
}
